//
//  VisitorLoginView.swift
//  Weibo
//
//  Created by 王少卓 on 16/1/20.
//  Copyright © 2016年 王少卓. All rights reserved.
//

import UIKit
//导入SnapKit命名空间
import SnapKit

class VisitorLoginView: UIView {
    
    //外界调用的重要方法
    func setupUIWithInfo(imageName: String?,tipText: String) {
        if let img = imageName {
        
            quanquan.image = UIImage(named: img)
            tipLabel.text = tipText
            //隐藏大房子
            largeHouse.hidden = true
            bringSubviewToFront(quanquan)
            
        } else {
            //说明在主页
            startAnimation()
        }
    
        
    }

    //圈圈的动画效果
    func startAnimation() {
        //基础动画
        let base = CABasicAnimation(keyPath: "transform.rotation")
        //设置重复次数
        base.repeatCount = MAXFLOAT
        base.toValue = 2 * M_PI
        //持续时间
        base.duration = 10
        //当页面市区活跃状态不移除动画
        base.removedOnCompletion = false
        //添加动画
        quanquan.layer.addAnimation(base, forKey: nil)
        
    }

    override init(frame: CGRect) {
        super.init(frame: frame)
        //设置ui
        setupUI()
        
    }

    //默认实现报错
    //当程序员通过sb或者xib加载该视图 就会崩溃
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setupUI() {
        //添加子视图
        addSubview(quanquan)
        addSubview(zhezhao)
        addSubview(largeHouse)
        addSubview(tipLabel)
        addSubview(loginBtn)
        addSubview(registerBtn)
        
        //设置自动布局  苹果代码布局是通过  VFL    但是基本不用

        //snp_makeConstraints表示添加一条约束
        quanquan.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(self.snp_centerX)
            make.centerY.equalTo(self.snp_centerY).offset(-80)
        }
        
        zhezhao.snp_makeConstraints { (make) -> Void in
//            make.center.equalTo(quanquan.snp_center)
            make.top.left.right.equalTo(self)
            make.bottom.equalTo(registerBtn.snp_bottom)
        }
        
        largeHouse.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(quanquan.snp_centerX)
            make.centerY.equalTo(quanquan.snp_centerY)
        }
        
        
        tipLabel.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(quanquan.snp_centerX)
            make.top.equalTo(quanquan.snp_bottom).offset(16)
            make.width.equalTo(225)
            make.height.equalTo(40)
        }
        
        
        loginBtn.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(tipLabel.snp_left)
            make.top.equalTo(tipLabel.snp_bottom).offset(20)
            make.width.equalTo(100)
        }
        
        registerBtn.snp_makeConstraints { (make) -> Void in
            make.right.equalTo(tipLabel.snp_right)
            make.top.equalTo(tipLabel.snp_bottom).offset(20)
            make.width.equalTo(100)
        }
        
        //设置背景颜色
        self.backgroundColor = UIColor(white: 0.93, alpha: 1)

    }
    
    //懒加载获取所有视图
    //遮罩图层
    lazy var zhezhao: UIImageView = UIImageView(image: UIImage(named: "visitordiscover_feed_mask_smallicon"))
    //1.圈圈图
    lazy var quanquan: UIImageView = UIImageView(image: UIImage(named: "visitordiscover_feed_image_smallicon"))

    //2房子
    lazy var largeHouse: UIImageView = UIImageView(image: UIImage(named: "visitordiscover_feed_image_house"))
    
    //3提示文字
    lazy var tipLabel: UILabel = {
        let l = UILabel()
        
        l.font = UIFont.systemFontOfSize(14)
        l.text = "关注一些人，回这里看看有什么惊喜"
        //设置自动换行
        l.numberOfLines = 0
        l.textColor = UIColor.darkGrayColor()
        //居中显示
        l.textAlignment = .Center
        //设置大小
        l.sizeToFit()
        return l
    }()
    //登录按钮
    lazy var loginBtn: UIButton = {
    
        let btn = UIButton()
        btn.setTitle("登录", forState: .Normal)
        btn.titleLabel?.font = UIFont.systemFontOfSize(18)
        btn.setTitleColor(UIColor.darkGrayColor(), forState: .Normal)
        btn.setBackgroundImage(UIImage(named: "common_button_white_disable"), forState: .Normal)
        
        return btn
    }()
    
    
    //注册按钮
    lazy var registerBtn: UIButton = {
        
        let btn = UIButton()
        btn.setTitle("注册", forState: .Normal)
        btn.titleLabel?.font = UIFont.systemFontOfSize(18)
        btn.setTitleColor(UIColor.orangeColor(), forState: .Normal)
        btn.setBackgroundImage(UIImage(named: "common_button_white_disable"), forState: .Normal)
        
        return btn
    }()

}














